package com.pascal91.webpp.dao;

import com.pascal91.webpp.model.Message;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MessageDaoImpl implements MessageDao{

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public List<Message> getMessagesList() {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Message.class);
        return criteria.list();
    }

    @Override
    public void addMessage(Message message) {
        sessionFactory.getCurrentSession().saveOrUpdate(message);
    }
}
